import threading
import time

import pyautogui
import win32gui
import keyboard
import ttkbootstrap as ttk
from pynput import mouse




# 设置pyautogui运行速度
pyautogui.PAUSE = 0.01
#获取屏幕尺寸
sizex,sizey=pyautogui.size()
print(sizex,sizey)
x=1
y=1
try:
        # 获取窗口句柄
        xzlt = win32gui.FindWindow('SelectForwardConversationWindow', '选择聊天')
        # 获取窗口左上角坐标和右下角坐标
        left, top, right, bottom = win32gui.GetWindowRect(xzlt)

        # 输出坐标信息
        print('窗口左上角坐标：({}, {})'.format(left, top))
        print('窗口右下角坐标：({}, {})'.format(right, bottom))
        # 设置窗口置顶
        win32gui.SetForegroundWindow(xzlt)
        x = left + 26
        y = bottom - 18
        print(x)
        print(y)
except Exception as e:
    print(e)
x1,y1=pyautogui.position() # 当前鼠标位置
print(x1)
print(y1)
def lx():

    # 移动鼠标
    #pyautogui.moveTo(x, y,duration=0.5)
    # pyautogui.mouseDown()
    # pyautogui.mouseUp()
    #pyautogui.moveTo(x, y)
    # 移动鼠标左击一下
    x1, y1 = pyautogui.position()  # 当前鼠标位置
    pyautogui.click(x, y)
    t2=time.time()
    pyautogui.press('down')


def run():

    print('代码执行中。。。。。。。。。。')

    keyboard.add_hotkey('f10', lx)

    keyboard.wait()


def chreadThread_run():

    t=threading.Thread(target=run)
    t.start()

chreadThread_run()
root = ttk.Window(themename="superhero")

# 窗口标题
root.title('连选器')
root.geometry('200x200')
root.resizable(0, 0)

run_button = ttk.Button(root, text='启动', command=chreadThread_run, bootstyle="success")
exit_button = ttk.Button(root, text='关闭', command=exit, bootstyle="success")
run_button.pack(pady=5, padx=10, ipadx=6)
exit_button.pack(pady=5, padx=10, ipadx=6)


# 进入主循环，显示窗口
root.mainloop()